package com.c2c.utils;


import com.c2c.po.Goods;
import com.c2c.po.User;

import java.util.Map;

/**
 * 用于返回拼装SQL语句
 * */
public class SQLProviderUtil {

    /**
     * UserMapper.updateCreditByUserId语句拼装
     * @param map   键值对  对应接口中条件.  param中里面的值为key ,封装的值为value
     * @return 返回对应拼装好的sql语句
     * */
    public String updateCreditByUserIdUtil(Map<String, Object> map){
        User user = (User) map.get("user");
        boolean type = (boolean) map.get("type");
        String sql = "update user set userCredit = userCredit";
//        String Sql = "update user set userCredit = userCredit "+"-"+" #{userCredit} where userAccount = #{userAccount}";
        if (type){
            sql = sql+" + ";
        }else {
            sql = sql+" - ";
        }
        sql= sql + user.getUserCredit() + " where userAccount = "+ user.getUserAccount();
        return sql;
    }

    /**
     * UserMapper.updateMoneyByUserId语句拼装
     * @param map   键值对  对应接口中条件.  param中里面的值为key ,封装的值为value
     * @return 返回对应拼装好的sql语句
     */
    public String updateMoneyByUserIdUtil(Map<String, Object> map){
        User user = (User) map.get("user");
        boolean type = (boolean) map.get("type");
        String sql = "update user set userMoney = userMoney";
        if (type){
            sql = sql+" + ";
        }else {
            sql = sql+" - ";
        }
        sql= sql + user.getUserMoney() + " where userAccount = "+ user.getUserAccount();
        return sql;
    }

    /**
     * UserMapper.updateMoneyByUserId语句拼装
     * @param map   键值对  对应接口中条件.  param中里面的值为key ,封装的值为value
     * @return 返回对应拼装好的sql语句
     */
    public String findBySomething(Map<String, Object> map){
        String string = String.valueOf(map.get("string"));
        int goodsClassifyId = (int) map.get("goodsClassifyId");
        String sql = "select * from goods where goodsName like '%"+string+"%' or goodsIntroduce like '%"+string+"%' or goodsTrait like '%"+string+"%' or goodsCondition like '%"+string+"%' ";
        if (goodsClassifyId != 0)
            sql = sql + " and goodsState = "+ goodsClassifyId ;
        return sql;
    }
}
